from UserSettingsPage import UserSettingsPage
from Autotests.LocalMachine.Controls.Button import WebButton
from Autotests.LocalMachine.Controls.Label import WebLabel
from Autotests.LocalMachine.UiObjectsMap.AirManager import UserSettings
from Autotests.LocalMachine.Pages.AirManager.MainPage import WebMainPage
from Autotests.LocalMachine.Pages.AirClient.MainPage import WebMainPage as ClientMain
from Autotests.WebDriver import DRIVER


class LicenseTab(UserSettingsPage):
    def __init__(self):
        super(LicenseTab, self).__init__()

    def goToHomeLocation(self):
        super(LicenseTab, self).goToHomeLocation()
        WebButton(UserSettings.btnLicense).click()

    def linkBuyNowClick(self):
        if WebMainPage().isTrial():
            self.goToHomeLocation()
            WebLabel(UserSettings.License.linkByNow).click()
            DRIVER().switch_to_window(DRIVER().window_handles[-1])
            return True
        else:
            return False

    def isBuyNowPageActive(self):
        return ClientMain().isBuyNowPageActive()
